home *** CD-ROM | disk | FTP | other *** search
- Path: cs.tu-berlin.de!news
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Help -- Problem with Protected Class in Borland 4.5
- Date: 29 Feb 1996 22:18:29 GMT
- Organization: Technical University of Berlin, Germany
- Message-ID: <4h58nl$5hf@news.cs.tu-berlin.de>
- NNTP-Posting-Host: 130.149.17.230
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
-
- edfollo@lovage.lerc.nasa.gov (Jeff Follo) writes:
- >
- > I'm using Borland C++ 4.5, trying to create either a DOS target or a EasyWin
- > target. I cannot get the following code to compile:
- >
- > #include <iostream.h>
- >
- > class BaseClass
- > {
- > public:
- > int a;
- > protected:
- > int b;
- > };
- >
- >
- > class UpperClass : public BaseClass
- > {
- > public:
- > void print_a() {cout << "\na = " << a;}
- > void print_b() {cout << "\nb = " << b;}
- > };
- >
- > void main()
- > {
- > UpperClass x;
- >
- > x.a = 1;
- > x.b = 2;
- >
- > x.print_a();
- > x.print_b();
- >
- > }
- >
- >
- > The error I get is:
- >
- > 'BaseClass::b' is not accessible in function main()
- >
- >
- > The code works if I comment out protected. What's wrong here?
- >
-
- You declare b protected in BaseClass and it remains protected in UpperClass.
- Logically, it's not accessible in main. Why do you declare b protected if
- you want to access it outside the class?
-
- Bye
-
- Roman
-
-